
using System.Collections;
using DG.Tweening;
using Gameplay.RTS.ScriptConfig;
using TMPro;
using UnityEngine;
using Yoozoo.Extension;
using Yoozoo.Managers.ResourceManagerV2.Runtime;
using Yoozoo.Gameplay.RTS;
using Random = UnityEngine.Random;
using System;
using Yoozoo.UI.YGUI;
using LogSystem;
using System.Collections.Generic;
using UnityEngine.UI;
using Yoozoo.Mars.Got;
using AudioStudio;
using Color = UnityEngine.Color;

namespace Gameplay.RTS.Hud
{
    public class WorldFlyText
    {
        public GameObject FlyText;
        protected int type;
        private bool isDestroyBySelf;
        private int poolType;
        public int id;
        public TMP_Text m_text;
        public SpriteRenderer m_icon;
        public TextMeshProUGUI m_textUGUI;
        private Animation m_flyAnimation;
        protected GameObject m_textPrefab;
        private const string ADD_VALUE = "+";
        private const string INDUCE_VALUE = "-";
        private static Vector3 normalOffset = new Vector3(0, 10.0f, -16.76f);
        protected FlyTextOffset _textOffsetConfig;
        private const float frameTime = 0.033f;
        private Coroutine m_animationCor;
        private const int Left = 1, Right = 2, IntoUp = 3, IntoInto = 4, SkillLeft = 5, SkillRight = 6, IntoIntoHeal = 7, IntoUpIcon = 8;
        //private bool isUI = false;
        private Transform[] children;
        private Vector3[] originalScale;
        private float defaultFontSize;
        private SpriteRenderer skillNameBg;
        private ContentSizeFitter sizeFitter;
        private SpriteContentSizeFitter spriteSizeFitter;
        private int[] flyNums = new int[10];// 技能伤害各阶段飘字缓存
        public int Type
        {
            get
            {
                return type;
            }
            set
            {
                type = value;
            }
        }
        public virtual void Create(GameObject prefab, int poolType)
        {
            this.poolType = poolType;
            FlyText = new GameObject("flyTextParent" + poolType);
            FlyText.transform.parent = FlyTextManager.FlyTextRoot;
            FlyText.transform.SetScale(1);
            FlyText.transform.localEulerAngles = Vector3.zero;
            FlyText.transform.position = new Vector3(-99999, -99999, -99999);
            /*children =*/
            var text = GameObject.Instantiate(prefab, FlyText.transform);
            this.m_textPrefab = text;

            children = m_textPrefab.GetComponentsInChildren<RectTransform>();
            originalScale = new Vector3[children.Length];
            for (int i = 0; i < originalScale.Length; i++)
            {
                originalScale[i] = children[i].localScale;
            }
            if (poolType == FlyTextManager.SkillNewOther || poolType == FlyTextManager.SkillNewSelf  || poolType == FlyTextManager.CarSkillOther || poolType == FlyTextManager.CarSkillSelf)
            {
                skillNameBg = m_textPrefab.GetComponentInChildren<SpriteRenderer>();
            }
            //text.SetActive(true);
            m_text = this.m_textPrefab.GetComponentInChildren<TMP_Text>();
            if (m_text != null)
            {
                m_text.fontSharedMaterial.SetFloat(ShaderUtilities.ShaderTag_ZTestMode, 0);
                m_text.alpha = 0;
                defaultFontSize = m_text.fontSize;
                sizeFitter = m_text.gameObject.GetComponent<ContentSizeFitter>();
            }
            
            m_textUGUI = m_textPrefab.GetComponentInChildren<TextMeshProUGUI>();
            if (m_textUGUI)
            {
                m_textUGUI.fontSharedMaterial.SetFloat(ShaderUtilities.ShaderTag_ZTestMode, 0);
                m_textUGUI.alpha = 0;
                defaultFontSize = m_text.fontSize;
                sizeFitter = m_textUGUI.gameObject.GetComponent<ContentSizeFitter>();
            }
            spriteSizeFitter = m_textPrefab.GetComponentInChildren<SpriteContentSizeFitter>();
            m_icon = this.m_textPrefab.GetComponentInChildren<SpriteRenderer>();
            //豪车飘字Icon 单独处理
            if (poolType == FlyTextManager.CarSkillOther || poolType == FlyTextManager.CarSkillSelf)
            {
                Transform iconTransform = m_textPrefab.transform.Find("root/bg/Text2/icon");
                if (iconTransform)
                {
                    SpriteRenderer sp = iconTransform.GetComponent<SpriteRenderer>();
                    if (sp)
                    {
                        m_icon = sp;
                    }
                }
            }
            if (m_icon !=null)
            {
                Color color = m_icon.color;
                color.a = 0;
                m_icon.color = color;
            }
            m_flyAnimation = m_textPrefab.GetComponentInChildren<Animation>();

        }

        public virtual void Update()
        {

        }
        public virtual void BackToPool()
        {
            if (m_animationCor != null)
            {
                UMTResource.Resource.StopCoroutine(m_animationCor);
            }
            FlyTextManager.AddToPool(this, poolType);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="position"></param>
        /// <param name="content"></param>
        /// <param name="scale"></param>
        /// <param name="targetPosition"></param>
        /// <param name="type"></param>
        /// <param name="audioType">是否播放音效</param>
        public virtual void Play(Vector3 position, string content, float scale, Vector3 targetPosition, int type, FlyTextAudio audioType = FlyTextAudio.NONE,string PlayAnimName = default)
        {
            if (this.type != type)
            {
                this.type = type;
                _textOffsetConfig = ArmyManager.Instance.ResourceManager.JsonManager.GetFlyTextOffsetByType(type);
            }
            if (_textOffsetConfig == null)
            {
                _textOffsetConfig = ArmyManager.Instance.ResourceManager.JsonManager.GetFlyTextOffsetByType(type);
            }
            if (children!=null)
            {
                for (int i = 0; i < children.Length; i++)
                {
                    children[i].localScale = originalScale[i];
                }
            }
            this.m_textPrefab.transform.localPosition = GetOffset();
            var ui = FlyText;
            var transform = ui.transform;
            transform.localScale = new Vector3(scale, scale, scale);
            transform.position = position;
            if (m_text != null)
            {
                m_text.alpha = 1;
                ColorUtility.TryParseHtmlString(_textOffsetConfig.VertextColor, out var color);
                m_text.color = color;
                if (_textOffsetConfig.FontSize > 0)
                {
                    m_text.fontSize = _textOffsetConfig.FontSize;
                }
                else
                {
                    m_text.fontSize = defaultFontSize;
                }
            }
         
            if (m_icon != null)
            {
                Color color = m_icon.color;
                color.a = 1;
                m_icon.color = color;
            }

            if (m_textUGUI)
            {
                ColorUtility.TryParseHtmlString(_textOffsetConfig.VertextColor, out var color);
                m_textUGUI.color = color;
            }
            if (type == FlyTextManager.GrabTrainDefeat || type == FlyTextManager.GrabTrainVictory)
            {
                // 列车要显示比分
                string[] str_contents = content.Split(',');
                content = str_contents[0];
                TMP_Text txt1 = m_textPrefab.transform.Find("root/UIParticle/Y_Extra1").GetComponent<TMP_Text>();
                txt1.text = str_contents[1];
                TMP_Text txt2 = m_textPrefab.transform.Find("root/UIParticle/Y_Extra2").GetComponent<TMP_Text>();
                txt2.text = str_contents[2];
            }
            
            //m_text.sortingOrder = 9999;
            if (this.m_text != null)
            {
                this.m_text.text = content;
            }
            if (m_textUGUI != null)
            {
                m_textUGUI.text = content;
            }
            if (spriteSizeFitter != null)
            {
                spriteSizeFitter.UpdateContent();
            }
            // || poolType == FlyTextManager.CarSkillOther || poolType == FlyTextManager.CarSkillSelf
            if (type == FlyTextManager.SkillNewSelf || type == FlyTextManager.SkillNewOther)
            {
                if (sizeFitter)
                {
                    sizeFitter.SetLayoutHorizontal();
                }
                skillNameBg.size = new Vector2(m_text.preferredWidth + 80, skillNameBg.size.y);
            }
            
            // if (type == FlyTextManager.CarSkillOther || type == FlyTextManager.CarSkillSelf)
            // {
            //     if (sizeFitter)
            //     {
            //         sizeFitter.SetLayoutHorizontal();
            //     }
            //     skillNameBg.size = new Vector2(m_text.preferredWidth + 80, skillNameBg.size.y);
            // }
            
            if (_textOffsetConfig.AnimationStyle == -1) //用动画播
            {
                if (m_flyAnimation != null)
                {
                    if (PlayAnimName!=default)
                    {
                        m_flyAnimation.Play(PlayAnimName);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(_textOffsetConfig.PlayAnimName))
                        {
                            DoTweenAnimation(IntoUp);
                        }
                        else
                        {
                            this.m_flyAnimation.Play(_textOffsetConfig.PlayAnimName);
                        }
                    }
                    
                }
                else
                {
                    Debug.LogErrorFormat(LogModule.RTS, $"类型{_textOffsetConfig.type}飘字未配置AnimationStyle字段（Dotween动画类型）且未含有Animation，请在flyTextOffset.json 配置\n 一种飘字必须含有动画或配置AnimationStyle 字段（dotween类型）");
                }
            }
            else //dotween
            {
                DoTweenAnimation(_textOffsetConfig.AnimationStyle);
            }

            //播放音效(如果有)
            if(audioType != FlyTextAudio.NONE)
            {
                string audioName = FlyTextManager.Instance.GetPlayAudioName(audioType);
                if (audioName != "")
                {
                    try
                    {
                        AudioManager.PlayVoice(audioName, ui.gameObject);
                    }
                    catch (Exception e) { }
                }
            }

            m_animationCor = UMTResource.Resource.StartCoroutine(PlayAnimationEnd());

        }
        internal void PlayRepeatText(Vector3 position, string numChar, int singleNum, float scale, Vector3 targetPosition, int type, List<int> intervalArray = null, string repeatPlayAnimName = default)
        {
            if (this.type != type)
            {
                this.type = type;
                _textOffsetConfig = ArmyManager.Instance.ResourceManager.JsonManager.GetFlyTextOffsetByType(type);
            }
            if (_textOffsetConfig == null)
            {
                _textOffsetConfig = ArmyManager.Instance.ResourceManager.JsonManager.GetFlyTextOffsetByType(type);
            }
            if (children != null)
            {
                for (int i = 0; i < children.Length; i++)
                {
                    children[i].localScale = originalScale[i];
                }
            }
            this.m_textPrefab.transform.localPosition = GetOffset();
            var ui = FlyText;
            var transform = ui.transform;
            transform.localScale = new Vector3(scale, scale, scale);
            transform.position = position;
            if (m_text != null)
            {
                m_text.alpha = 1;
                ColorUtility.TryParseHtmlString(_textOffsetConfig.VertextColor, out var color);
                color.a = 0;
                m_text.color = color;
                if (_textOffsetConfig.FontSize > 0)
                {
                    m_text.fontSize = _textOffsetConfig.FontSize;
                }
                else
                {
                    m_text.fontSize = defaultFontSize;
                }
            }

            if (m_textUGUI)
            {
                ColorUtility.TryParseHtmlString(_textOffsetConfig.VertextColor, out var color);
                color.a = 0;
                m_textUGUI.color = color;
            }
            if (this.m_text != null)
            {
                this.m_text.text = $"{numChar}{singleNum}";
            }
            if (m_textUGUI != null)
            {
                m_textUGUI.text = $"{numChar}{singleNum}";
            }

            if (intervalArray!=null)
            {
                for (int i = 0; i < intervalArray.Count; i++)
                {
                    int temp = i;
                    Timers.inst.Add((float)intervalArray[i] / 1000, 1, (obj) =>
                    {
                        if (m_flyAnimation != null)
                        {
                            if (this.m_text != null)
                            {
                                this.m_text.text = $"{numChar}{(temp + 1)* singleNum}";
                            }
                            if (m_textUGUI != null)
                            {
                                m_textUGUI.text = $"{numChar}{(temp + 1) * singleNum}";
                            }

                            ResetAnimation(m_flyAnimation, repeatPlayAnimName, temp);
                            m_flyAnimation.Play(repeatPlayAnimName);
                        }
                    });
                }
                m_animationCor = UMTResource.Resource.StartCoroutine(PlayRepeatAnim(intervalArray[intervalArray.Count - 1] / 1000 + 2));
            }
        }
        internal void PlayRepeatText2(Vector3 position, string numChar, int allNum, float scale, Vector3 targetPosition, int type, List<Vector2Int> intervalArray = null, string repeatPlayAnimName = default)
        {
            if (this.type != type)
            {
                this.type = type;
                _textOffsetConfig = ArmyManager.Instance.ResourceManager.JsonManager.GetFlyTextOffsetByType(type);
            }
            if (_textOffsetConfig == null)
            {
                _textOffsetConfig = ArmyManager.Instance.ResourceManager.JsonManager.GetFlyTextOffsetByType(type);
            }
            if (children != null)
            {
                for (int i = 0; i < children.Length; i++)
                {
                    children[i].localScale = originalScale[i];
                }
            }
            this.m_textPrefab.transform.localPosition = GetOffset();
            var ui = FlyText;
            var transform = ui.transform;
            transform.localScale = new Vector3(scale, scale, scale);
            transform.position = position;
            if (m_text != null)
            {
                m_text.alpha = 1;
                ColorUtility.TryParseHtmlString(_textOffsetConfig.VertextColor, out var color);
                color.a = 0;
                m_text.color = color;
                if (_textOffsetConfig.FontSize > 0)
                {
                    m_text.fontSize = _textOffsetConfig.FontSize;
                }
                else
                {
                    m_text.fontSize = defaultFontSize;
                }
            }

            if (m_textUGUI)
            {
                ColorUtility.TryParseHtmlString(_textOffsetConfig.VertextColor, out var color);
                color.a = 0;
                m_textUGUI.color = color;
            }
            // 计算一下各阶段伤害值
            int allSub = 0;
            for (int i = 0; i < intervalArray.Count; i++)
            {
                allSub += intervalArray[i].y;
            }
            if (allSub == 0)
            {
                allSub = intervalArray.Count;
            }
            int showNum = 0;
            for (int i = 0; i < intervalArray.Count; i++)
            {
                showNum +=  (allNum / allSub) * intervalArray[i].y;
                if (i == intervalArray.Count - 1)
                {
                    flyNums[i] = allNum;
                }
                else
                {
                    flyNums[i] = showNum;
                }
            }

            if (this.m_text != null && intervalArray != null)
            {
                this.m_text.text = $"{numChar}{flyNums[0]}";
            }
            if (m_textUGUI != null && intervalArray != null)
            {
                m_textUGUI.text = $"{numChar}{flyNums[0]}";
            }

            if (intervalArray!=null)
            {
                for (int i = 0; i < intervalArray.Count; i++)
                {
                    int temp = i;
                    Timers.inst.Add((float)intervalArray[i].x / 1000, 1, (obj) =>
                    {
                        if (m_flyAnimation != null)
                        {
                            if (this.m_text != null)
                            {
                                this.m_text.text = $"{numChar}{flyNums[temp]}";
                            }
                            if (m_textUGUI != null)
                            {
                                m_textUGUI.text = $"{numChar}{flyNums[temp]}";
                            }

                            ResetAnimation(m_flyAnimation, repeatPlayAnimName, temp);
                            m_flyAnimation.Play(repeatPlayAnimName);
                        }
                    });
                }
                m_animationCor = UMTResource.Resource.StartCoroutine(PlayRepeatAnim(intervalArray[intervalArray.Count - 1].x / 1000 + 2));
            }
        }

        private IEnumerator PlayRepeatAnim(float time)
        {
            yield return new WaitForSeconds(time);
            this.BackToPool();
        }
        private void ResetAnimation(Animation ani, string name, int temp)
        {
            AnimationState state = ani[name];
            state.normalizedTime = 0;
        }

        public virtual Vector3 GetOffset()
        {
            Vector3 offset = Vector3.zero;
            if (_textOffsetConfig == null)
            {
                return offset;
            }
            offset = new Vector3(_textOffsetConfig.x, _textOffsetConfig.y, _textOffsetConfig.z);
            if (_textOffsetConfig.isRandom)
            {
                offset = offset + RandomSkillOffset();
            }
            return offset;
        }

        public Vector3 RandomSkillOffset()
        {
            var ratio = Random.Range(0, 10) > 5 ? 1 : -1;
            var offsetx = Random.Range(_textOffsetConfig.randomXmin, _textOffsetConfig.randomXmax) * ratio;
            var offsety = Random.Range(_textOffsetConfig.randomYmin, _textOffsetConfig.randomYmax);
            return new Vector3(offsetx, offsety, 0);
        }

     

        protected IEnumerator PlayAnimationEnd()
        {
            yield return new WaitForSeconds(2.0f);
           this.BackToPool();
        }

        public void recover()
        {
            if (m_text!=null)
            {
                m_text.alpha = 0;
            }

            if (m_icon != null)
            {
                Color color = m_icon.color;
                color.a = 0;
                m_icon.color = color;
            }
        }

        private void DoTweenAnimation(int style)
        {
            switch (style)
            {
                case Left:
                    Sequence leftSequeue = DOTween.Sequence();
                    var localPos = m_textPrefab.transform.localPosition;
                    leftSequeue.Insert(0, DOTween.To(() => { return 1f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1.55f, frameTime * 3).SetEase(Ease.OutQuad));

                    leftSequeue.Insert(frameTime * 3, DOTween.To(() => { return 1.55f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 0.9f, frameTime * 2f).SetEase(Ease.InOutQuad));

                    leftSequeue.Insert(frameTime * 5, DOTween.To(() => { return 0.9f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 0.6f, frameTime * 20).SetEase(Ease.InQuad));

                    var Pos2Start = new Vector3(localPos.x - 6, localPos.y + 10.5f, localPos.z);
                    var Pos2End = new Vector3(Pos2Start.x - 4f, Pos2Start.y - 1f, Pos2Start.z);

                    leftSequeue.Insert(0, DOTween.To(() => { return localPos; }, (Vector3 position) =>
                    {
                        m_textPrefab.transform.localPosition = position;
                    }, Pos2Start, frameTime * 17));

                    leftSequeue.Insert(frameTime * 17, DOTween.To(() => { return Pos2Start; }, (Vector3 position) =>
                    {
                        m_textPrefab.transform.localPosition = position;
                    }, Pos2End, frameTime * 10).SetEase(Ease.InQuad));

                    leftSequeue.Insert(frameTime * 17, DOTween.To(() => { return 1; }, (float alpha) =>
                    {
                        m_text.alpha = alpha;
                    }, 0, frameTime * 10).SetEase(Ease.InOutQuad));
                    leftSequeue.Play();
                    break;
                case Right:
                    Sequence rightSequeue = DOTween.Sequence();
                    localPos = m_textPrefab.transform.localPosition;
                    rightSequeue.Insert(0, DOTween.To(() => { return 1f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1.55f, frameTime * 3).SetEase(Ease.OutCubic));

                    rightSequeue.Insert(frameTime * 3, DOTween.To(() => { return 1.55f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 0.9f, frameTime * 2f).SetEase(Ease.InOutQuad));

                    rightSequeue.Insert(frameTime * 5, DOTween.To(() => { return 0.9f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 0.6f, frameTime * 20).SetEase(Ease.InQuad));

                    Pos2Start = new Vector3(localPos.x + 6, localPos.y + 10.5f, localPos.z);
                    Pos2End = new Vector3(Pos2Start.x + 4f, Pos2Start.y - 1f, Pos2Start.z);

                    rightSequeue.Insert(0, DOTween.To(() => { return localPos; }, (Vector3 position) =>
                    {
                        m_textPrefab.transform.localPosition = position;
                    }, Pos2Start, frameTime * 17));

                    rightSequeue.Insert(frameTime * 17, DOTween.To(() => { return Pos2Start; }, (Vector3 position) =>
                    {
                        m_textPrefab.transform.localPosition = position;
                    }, Pos2End, frameTime * 10).SetEase(Ease.InQuad));

                    rightSequeue.Insert(frameTime * 17, DOTween.To(() => { return 1; }, (float alpha) =>
                    {
                        m_text.alpha = alpha;
                    }, 0, frameTime * 10).SetEase(Ease.InOutQuad));
                    rightSequeue.Play();
                    break;

                case IntoUp:
                    Sequence sequence = DOTween.Sequence();
                    sequence.Append(DOTween.To(() => { return 0.8f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1.5f, frameTime * 5));
                    sequence.Append(DOTween.To(() => { return 1.5f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1, frameTime * 2));
                     sequence.Insert(0f,DOTween.To(() => { return m_textPrefab.transform.localPosition.y; }, (float posY) =>
                    {
                        var pos = m_textPrefab.transform.localPosition;
                        m_textPrefab.transform.localPosition = new Vector3(pos.x, posY, pos.z);
                    }, m_textPrefab.transform.localPosition.y + 3f, frameTime * 7).SetEase(Ease.InOutSine));
                    sequence.Insert(1.1f,DOTween.To(() => { return m_textPrefab.transform.localPosition.y; }, (float posY) =>
                    {
                        var pos = m_textPrefab.transform.localPosition;
                        m_textPrefab.transform.localPosition = new Vector3(pos.x, posY, pos.z);
                    }, m_textPrefab.transform.localPosition.y + 5f, frameTime * 10).SetEase(Ease.InQuart));
                    sequence.Insert(1.1f, DOTween.To(() => { return 1f; }, (float alpha) =>
                    {
                        m_text.alpha = alpha;
                    }, 0f, frameTime * 15));
                    sequence.Play();
                    break;
                case IntoInto:
                    Sequence intoInto = DOTween.Sequence();
                    intoInto.Insert(0f, DOTween.To(() => { return 0.7f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1.1f, frameTime * 7).SetEase(Ease.OutQuad));

                    intoInto.Insert(frameTime * 6f, DOTween.To(() => { return 1.1f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1f, frameTime * 10).SetEase(Ease.OutQuad));

                    intoInto.Insert(frameTime * 17f, DOTween.To(() => { return 1f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1f, frameTime * 15));

                    intoInto.Insert(frameTime * 32f, DOTween.To(() => { return 1f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 0.7f, frameTime * 8).SetEase(Ease.InQuad));

                    intoInto.Insert(0f, DOTween.To(() => { return 1f; }, (float alpha) =>
                    {
                        m_text.alpha = alpha;
                    }, 1f, frameTime * 7));

                    intoInto.Insert(frameTime * 32, DOTween.To(() => { return 1f; }, (float alpha) =>
                    {
                        m_text.alpha = alpha;
                    }, 0f, frameTime * 8));
                    intoInto.Insert(0.0f, DOTween.To(() => { return m_textPrefab.transform.localPosition.y; }, (float posY) =>
                    {
                        var pos = m_textPrefab.transform.localPosition;
                        m_textPrefab.transform.localPosition = new Vector3(pos.x, posY, pos.z);
                    }, m_textPrefab.transform.localPosition.y + 9.5f, frameTime * 10).SetEase(Ease.InQuart));

                    intoInto.Play();
                    break;
                default:
                    break;
                case SkillLeft:
                    DoSkillLeft();
                    break;
                case SkillRight:
                    DoSkillRight();
                    break;
                case IntoIntoHeal:
                    DoIntoHeal();
                    break;
                case IntoUpIcon:
                    DoIntoUpIcon();
                    break;
            }
        }

        private void DoIntoUpIcon()
        {
            Sequence sequence = DOTween.Sequence();
            sequence.Append(DOTween.To(() => { return 2.5f; }, (float scale) =>
            {
                m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
            }, 0.9f, frameTime * 5));
            sequence.Append(DOTween.To(() => { return 0.9f; }, (float scale) =>
            {
                m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
            }, 1, frameTime * 5));
            sequence.Insert(0.825f, DOTween.To(() => { return 1f; }, (float alpha) =>
            {
                m_text.alpha = alpha;
                Color color = m_icon.color;
                color.a = alpha;
                m_icon.color = color;
            }, 0f, frameTime * 8));
            sequence.Insert(0.825f, DOTween.To(() => { return m_textPrefab.transform.localPosition.y; }, (float posY) =>
            {
                var pos = m_textPrefab.transform.localPosition;
                m_textPrefab.transform.localPosition = new Vector3(pos.x, posY, pos.z);
            }, m_textPrefab.transform.localPosition.y + 6.5f, frameTime * 8).SetEase(Ease.InQuart));
            sequence.Play();
        }


        /// <summary>
        /// 技能飘字右
        /// </summary>
        private void DoSkillRight()
        {
            Sequence sequence = DOTween.Sequence();
                    sequence.Append(DOTween.To(() => { return 0.8f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 2f, frameTime * 5));
                    sequence.Append(DOTween.To(() => { return 2f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 0.9f, frameTime * 3));
                     sequence.Append(DOTween.To(() => { return 0.9f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1f, frameTime * 3));
                    sequence.Insert(1f,DOTween.To(() => { return m_textPrefab.transform.localPosition.y; }, (float posY) =>
                    {
                        var pos = m_textPrefab.transform.localPosition;
                        m_textPrefab.transform.localPosition = new Vector3(pos.x, posY, pos.z);
                    }, m_textPrefab.transform.localPosition.y + 5f, frameTime * 10).SetEase(Ease.InQuart));
                    sequence.Insert(1f, DOTween.To(() => { return 1f; }, (float alpha) =>
                    {
                        m_text.alpha = alpha;
                    }, 0f, frameTime * 10));
                    sequence.Play();
        }

        /// <summary>
        /// 技能飘字左
        /// </summary>
        private void DoSkillLeft()
        {
             Sequence sequence = DOTween.Sequence();
                    sequence.Append(DOTween.To(() => { return 0.8f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 2f, frameTime * 5));
                    sequence.Append(DOTween.To(() => { return 2f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 0.9f, frameTime * 3));
                     sequence.Append(DOTween.To(() => { return 0.9f; }, (float scale) =>
                    {
                        m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
                    }, 1f, frameTime * 2));
                    sequence.Insert(1f,DOTween.To(() => { return m_textPrefab.transform.localPosition.y; }, (float posY) =>
                    {
                        var pos = m_textPrefab.transform.localPosition;
                        m_textPrefab.transform.localPosition = new Vector3(pos.x, posY, pos.z);
                    }, m_textPrefab.transform.localPosition.y + 5f, frameTime * 10).SetEase(Ease.InQuart));
                    sequence.Insert(1f, DOTween.To(() => { return 1f; }, (float alpha) =>
                    {
                        m_text.alpha = alpha;
                    }, 0f, frameTime * 10));
                    sequence.Play();
        }

        /// <summary>
        /// 技能名字
        /// </summary>
        private void DoIntoHeal()
        {
            Sequence intoInto = DOTween.Sequence();
            var localPos = m_textPrefab.transform.localPosition;
            intoInto.Insert(0f, DOTween.To(() => { return 3f; }, (float scale) =>
            {
                m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
            }, 0.9f, frameTime * 4).SetEase(Ease.OutQuad));

            intoInto.Insert(frameTime * 4f, DOTween.To(() => { return 0.9f; }, (float scale) =>
            {
                m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
            }, 1f, frameTime * 2).SetEase(Ease.OutQuad));

            intoInto.Insert(frameTime * 6f, DOTween.To(() => { return 1f; }, (float scale) =>
            {
                m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
            }, 1.05f, frameTime * 15));

            intoInto.Insert(frameTime * 21f, DOTween.To(() => { return 1f; }, (float scale) =>
            {
                m_textPrefab.transform.localScale = new Vector3(scale, scale, scale);
            }, 0.8f, frameTime * 7).SetEase(Ease.InQuad));

            var Pos2Start = new Vector3(localPos.x, localPos.y + 3f, localPos.z);

            intoInto.Insert(21f * frameTime, DOTween.To(() => { return localPos; }, (Vector3 position) =>
            {
                m_textPrefab.transform.localPosition = position;
            }, Pos2Start, frameTime * 7f).SetEase(Ease.InQuad));

            intoInto.Insert(0f, DOTween.To(() => { return 1f; }, (float alpha) =>
            {
                m_text.alpha = alpha;
            }, 1f, frameTime * 3));

            intoInto.Insert(frameTime * 25, DOTween.To(() => { return 1f; }, (float alpha) =>
            {
                m_text.alpha = alpha;
            }, 0f, frameTime * 3));

            intoInto.Play();
        }

        public Transform GetTextTransform()
        {
            return m_textPrefab.transform;
        }
    }
}

